package com.perye.dokit.service.impl;

import com.perye.dokit.mapper.dao.DaoSupport;
import com.perye.dokit.service.DictDetailService;
import com.perye.dokit.service.WeddingAppService;
import com.perye.dokit.service.WeddingTypeService;
import com.perye.dokit.utils.StringUtils;
import com.perye.dokit.utils.pageData.PageData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * @ClassName WeddingAppServiceImpl
 * @Description app接口实现类
 * @Date 2022/3/21 15:29
 * @Version 1.0
 **/
@Service
public class WeddingAppServiceImpl implements WeddingAppService {

    @Resource(name = "daoSupport")
    private DaoSupport dao;

    @Autowired
    private DictDetailService dictDetailService;

    @Override
    public List<PageData> queryWeddingType(PageData pageData) throws Exception {
        List<PageData> weddingTypeList = (List<PageData>) dao.findForList("WeddingAppMapper.queryWeddingType", pageData);
        if (!CollectionUtils.isEmpty(weddingTypeList)) {
            for (PageData weddingType : weddingTypeList) {
                String imageUrl = weddingType.getString("imageUrl");
                if (StringUtils.isBlank(imageUrl)) {
                    weddingType.put("imageUrl", "");
                }
            }
        }
        return weddingTypeList;
    }

    @Override
    public List<PageData> queryPersonnel(PageData pageData) throws Exception {
        List<PageData> personnelList = (List<PageData>) dao.findForList("WeddingAppMapper.queryPersonnel", pageData);

        if (!CollectionUtils.isEmpty(personnelList)) {
            Map<String, String> typeMap = dictDetailService.queryDictDetailByName("personnel_type", "map");
            for (PageData personnel : personnelList) {
                String type = personnel.get("type") + "";
                if (StringUtils.isNotBlank(typeMap.get(type))) {
                    personnel.put("type", typeMap.get(type));
                }

                int sex = (int) personnel.get("sex");
                if (sex == 0) {
                    personnel.put("sex", "女");
                } else {
                    personnel.put("sex", "男");
                }

                String imageUrl = personnel.getString("imageUrl");
                if (StringUtils.isBlank(imageUrl)) {
                    personnel.put("imageUrl", "");
                }

                String imageId = personnel.getString("imageId");
                if (StringUtils.isBlank(imageId)) {
                    personnel.put("imageId", "");
                }

                String videoUrl = personnel.getString("videoUrl");
                if (StringUtils.isBlank(videoUrl)) {
                    personnel.put("videoUrl", "");
                }

                String videoId = personnel.getString("videoId");
                if (StringUtils.isBlank(videoId)) {
                    personnel.put("videoId", "");
                }
            }
        }

        return personnelList;
    }
}
